package com.liuhan.house.controller;


import com.github.pagehelper.PageInfo;
import com.liuhan.house.pojo.User;
import com.liuhan.house.service.AgencyService;
import com.liuhan.house.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class AgencyController {
    @Autowired
    private UserService userService;
    @Autowired
    private AgencyService agencyService;

    /**
     * 跳转到中介详情页面
     */
    @RequestMapping("page/agency")
    public String pageAgency() {
        return "/user/agency/agentList";
    }

    /**
     * 根据userId查询
     */
    @RequestMapping("user/agency")
    public String getAgencyById(@RequestParam("userId") Integer userId, ModelMap modelMap) {
        User agencyUser = userService.selectByPrimaryKey(userId);
        modelMap.put("agencyUser", agencyUser);
        return "/user/agency/agencyDetail";
    }

    /**
     * 带分页查询中介人集合
     */
    @RequestMapping("user/agency/list")
    public String getAgencyList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                @RequestParam(value = "pageSize", defaultValue = "4") Integer pageSize,
                                ModelMap modelMap) {
        PageInfo<User> userPageInfo = userService.getAgencyList(pageNum, pageSize);
        modelMap.put("userPageInfo", userPageInfo);
        return "/user/agency/agentList";
    }


    /**
     * 带分页查询中介集合
     */
    @RequestMapping("user/agencyName/list")
    public String getAgencyNameList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                @RequestParam(value = "pageSize", defaultValue = "4") Integer pageSize,
                                ModelMap modelMap) {
        PageInfo<User> agencyName = agencyService.getAgencyNameList(pageNum, pageSize);
        modelMap.put("agencyName", agencyName);
        return "";
    }

}
